
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author personal
 */
public class DisablePortraitCanvas extends Canvas {

    private NinjaRunMIDlet midlet;
    private AnimatedSprite spShadow;
    //private static int FRAME_SHADOW_WIDTH = 0;
    //private static int FRAME_SHADOW_HEIGHT = 0;
    private LayerManager lmgr;
    //private String pathShadow = "";
    private String pathDisable = "";
    private Image imgDisable;
    private boolean running = false;
    private int loop = 0;
    public boolean isDisablePortrait = false;

    public DisablePortraitCanvas(NinjaRunMIDlet midlet) {
        //uper(true);
        this.midlet = midlet;
        setFullScreenMode(true);


        /*
        if (getWidth() == 640) {
        FRAME_SHADOW_WIDTH = 46;
        FRAME_SHADOW_HEIGHT = 49;
        pathShadow = "/black-shadow640.png";
        pathTitle = "/titleNinjaRun640.png";
        } else if (getWidth() > 320) {
        isDisablePortrait = true;
        } else {
        FRAME_SHADOW_WIDTH = 23;
        FRAME_SHADOW_HEIGHT = 25;
        pathShadow = "/black-shadow320.png";
        pathTitle = "/titleNinjaRun320.png";
        }        
        
        
        try {
        //animated sprite
        spShadow = new AnimatedSprite(Image.createImage(pathShadow),
        FRAME_SHADOW_WIDTH, FRAME_SHADOW_HEIGHT);
        spShadow.defineReferencePixel(FRAME_SHADOW_WIDTH / 2, FRAME_SHADOW_HEIGHT / 2);
        
        lmgr = new LayerManager();
        lmgr.append(spShadow);
        
        spShadow.setRefPixelPosition(getWidth()/2 - spShadow.getWidth(), getHeight()/2);
        } catch (IOException ex) {
        }
        
         * 
         */
        pathDisable = "/disableportrait.png";
        try {
            imgDisable = Image.createImage(pathDisable);
        } catch (IOException ex) {
        }

        //new Thread(this).start();
        //setFullScreenMode(true);

    }

    /*
    private void dismiss() {
    if (isShown()) {
    host.showMenuCanvas();
    }
    }
     * 
     */
    protected void paint(Graphics g) {
        if (isDisablePortrait) {
            g.drawImage(imgDisable, 0, 0, Graphics.TOP | Graphics.LEFT);
        }
    }

    protected void sizeChanged(int w, int h) {
        super.sizeChanged(w, h);
        if (getWidth() > getHeight()) {
            isDisablePortrait = false;
        } else {
            isDisablePortrait = true;
        }
    }
}
